uniform float pointRadius;
uniform vec3 lightDir = vec3(0.577, 0.577, 0.577);

void main()
{
    // calculate eye-space sphere normal from texture coordinates
    vec3 N;
    N.xy = gl_TexCoord[0].xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
    float r2 = dot(N.xy, N.xy);
    if (r2 > 1.0) discard;   // kill pixels outside circle
    N.z = sqrt(1.0-r2);

    // calculate depth
    vec4 eyeSpacePos = vec4(gl_TexCoord[1].xyz + N*pointRadius, 1.0);   // position of this pixel on sphere in eye space
    vec4 clipSpacePos = gl_ProjectionMatrix * eyeSpacePos;
    gl_FragDepth = (clipSpacePos.z / clipSpacePos.w)*0.5+0.5;

    float diffuse = max(0.0, dot(N, lightDir));

    gl_FragColor = diffuse*gl_Color;
}